package com.loong.game2048.module.vo;

import com.loong.game2048.module.Forum;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * 分页封装帖子
 */
@Data
public class  PaginationVo<T> {
    private List<T> datas;
    //是否还有上一页
    private boolean showPrevious;
    private boolean showFirstPage;
    //是否还有下一页
    private boolean showNext;
    private boolean showEndPage;
    //当前页数
    private Integer page;
    //页数列表
    private List<Integer> pages = new ArrayList<>();
    private Integer totalPage;

    public void setPagination(Integer totalPage, Integer page){
        this.totalPage = totalPage;
        this.page = page;
        pages.add(page);
        //展示当前页数的前三页、后三页
        for (int i = 1; i <= 3 ; i++) {
            if (page - i > 0){
                pages.add(0,page - i);
            }

            if (page + i <= totalPage){
                pages.add(page + i);
            }
        }

        //是否展示上一页
        if (page == 1){
            showPrevious = false;
        }else {
            showPrevious = true;
        }

        //是否展示下一页
        if (page == totalPage){
            showNext = false;
        }else {
            showNext = true;
        }

        //是否展示第一页
        if (pages.contains(1)){
            showFirstPage = false;
        }else {
            showFirstPage = true;
        }

        //是否展示最后一页
        if (pages.contains(totalPage)){
            showEndPage = false;
        }else {
            showEndPage = true;
        }

    }

}
